$(function () {
    $('#captcha-btn').click(function (event) {
        event.preventDefault();
        var email = $('input[type="email"]').val();
        if(!email) {
            zlalert.alertInfoToast('请输入邮箱');
            return;
        }
        zlajax.get({
            'url': '/cms/email_captcha/',
            'data': {
                'email': email
            },
            'success': function (data) {
                if (data['code'] === 200){
                    zlalert.alertSuccessToast('邮件发送成功，请注意查收。');
                } else {
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail': function (error) {
                zlalert.alertNetworkError();
            }
        })
    });

    $('#captcha_submit').click(function (event) {
        console.log('in resetemail.js captcha_submit');
        event.preventDefault();
        var emailE = $('input[type="email"]');
        var captchaE = $('input[name="captcha"]');

        var email = emailE.val();
        var captcha = captchaE.val();

        zlajax.post({
            'url': '/cms/resetemail/',
            'data': {
                'email': email,
                'captcha': captcha
            },
            'success': function (data) {
                if (data['code'] === 200) {
                    zlalert.alertSuccessToast("修改邮箱成功");
                    captchaE.val("");
                    emailE.val("");
                } else {
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail': function (error) {
                zlalert.alertNetworkError();
            }
        });
    });
});

// $(function () {
//
// });